package com.qm.datax.beans;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author：wangshali
 * @CreateTime：2024-10-31
 * @Description：
 * @Source:
 * @Sink:
 * @Version：v1.0 -----------------------------------------------------------------------------------
 * mysql                                                hive                           ck                       datax
 * --varchar,char,text,Date,datetime,timestamp       --string                       --String                    --String
 * --bigint,int,smallint                             --bigint                       --Int64                     --Long
 * --bit,tinyint                                     --tinyint                      --Int8                      --Long
 * --double,float,decimal                            --decimal                      --Decimal                   --Double
 * --
 * <p>
 * -----------------------------------------------------------------------------------

 */

public class Column {
    private final String name;
    private final String type;
    private final String hiveType;
    private static final Map<String, String> typeMap = new HashMap<>();

    static {
        //mysql类型 -- datax类型
        typeMap.put("bigint", "bigint");
        typeMap.put("int", "bigint");
        typeMap.put("smallint", "bigint");
        typeMap.put("tinyint", "tinyint");
        typeMap.put("bit", "tinyint");
        typeMap.put("double", "double");
        typeMap.put("float", "double");
        //ck类型 --datax类型
        // typeMap.put("Decimal(18,4)", "double");bug
        typeMap.put("Int8", "long");
        typeMap.put("Int64", "long");
        typeMap.put("String", "string");
        typeMap.put("Date", "string");
        typeMap.put("DateTime", "string");
    }


    public Column(String name, String type) {
        this.name = name;
        this.type = type;
        if (type.contains("Decimal") || type.contains("decimal") ) {
            this.hiveType = typeMap.getOrDefault(type, "double");
        } else {
            this.hiveType = typeMap.getOrDefault(type, "string");
        }
    }


    public String name() {
        return name;
    }

    public String type() {
        return type;
    }

    public String hiveType() {
        return hiveType;
    }

}
